package com.xue.web.servlet;

import com.alibaba.fastjson.JSONObject;
import com.xue.web.controller.RegisterController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class RegisterServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决火狐解析格式不佳
        resp.setContentType("text/html;charset=utf-8");
        JSONObject jsonObject;
        System.out.println(this.getClass().getSimpleName()+"|收到请求并分发");
        //将请求分发给 controller
        String requestURI = req.getRequestURI();
        if (requestURI.endsWith("registerServlet")){
            RegisterController registerController =new RegisterController();
            jsonObject = registerController.starRegister(req, resp);
            resp.getWriter().write(jsonObject.toJSONString());
        }

    }
}
